/*
  Created on Jun 22, 2005
  (C) 2005 
  @author Michael Long

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package sxe.core.math;

import snobject.snDouble;
import snobject.snInteger;
import snobject.snObject;
import snobject.snObjectArgList;
import step.EvaluationFailure;
import step.FunctionWrapper;

public class compareto extends FunctionWrapper {

	public snObject Call(snObjectArgList argv) throws EvaluationFailure {
		boolean isDbl = false;
		Double d1 = 0.0, d2 = 0.0;
		Integer i1 = 0, i2 = 0;
		
		int index = argv.index();
		if(argv.popObject() instanceof snDouble){
			d1 = ((snDouble)argv.objectAt(index)).getDouble();
			index++;
			if(!(argv.popObject() instanceof snDouble))
				throw new ClassCastException();
			d2 = ((snDouble)argv.objectAt(index)).getDouble();
			isDbl = true;
		}
		else{
			i1 = ((snInteger)argv.objectAt(index)).getInteger();
			index++;
			if(!(argv.popObject() instanceof snInteger))
				throw new ClassCastException();
			i2 = ((snInteger)argv.objectAt(index)).getInteger();
		}
				
		if(isDbl)
			return new snDouble(new Integer(d1.compareTo(d2)));
		else
		return new snInteger(new Integer(i1.compareTo(i2)));
	}

}
